﻿using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;

namespace Chat.Framework
{
    public class EncryptionAndDecryption
    {
        private const string key = "d509088b";
        private const string iv = "a07b70e3";

        //加密
        public static string TripleDESEncrypting(string encryptedValue)
        {
            return encryptedValue;
            //using (DESCryptoServiceProvider sa =
            //    new DESCryptoServiceProvider
            //        {Key = Encoding.UTF8.GetBytes(key), IV = Encoding.UTF8.GetBytes(iv)})
            //{
            //    using (ICryptoTransform ct = sa.CreateDecryptor())
            //    {
            //        byte[] byt = Convert.FromBase64String(encryptedValue);

            //        using (var ms = new MemoryStream())
            //        {
            //            using (var cs = new CryptoStream(ms, ct, CryptoStreamMode.Write))
            //            {
            //                cs.Write(byt, 0, byt.Length);
            //                cs.FlushFinalBlock();
            //            }

            //            return Encoding.UTF8.GetString(ms.ToArray());
            //        }
            //    }
            //}
        }

        /// <summary>
        /// 解密
        /// </summary>
        /// <param name="originalValue"></param>
        /// <returns></returns>
        public static string TripleDESDecrypting(string originalValue)
        {
            return originalValue;
            //using (DESCryptoServiceProvider sa
            //    = new DESCryptoServiceProvider {Key = Encoding.UTF8.GetBytes(key), IV = Encoding.UTF8.GetBytes(iv)})
            //{
            //    using (ICryptoTransform ct = sa.CreateEncryptor())
            //    {
            //        byte[] by = Encoding.UTF8.GetBytes(originalValue);
            //        using (var ms = new MemoryStream())
            //        {
            //            using (var cs = new CryptoStream(ms, ct,
            //                CryptoStreamMode.Write))
            //            {
            //                cs.Write(by, 0, by.Length);
            //                cs.FlushFinalBlock();
            //            }

            //            return Convert.ToBase64String(ms.ToArray());
            //        }
            //    }
            //}
        }
    }
}
